package com.example.dp01.aop;

import com.example.dp01.constant.REnum;
import com.example.dp01.exception.RException;
import com.example.dp01.util.RUtil;
import com.example.dp01.vo.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionHandle {
    @ExceptionHandler(value=Exception.class)
    public R handle(Exception e){
        if(e instanceof Exception){
            RException rException = (RException) e;
            return RUtil.error(rException.getCode(),rException.getMessage());
        }
        return RUtil.error(REnum.UNKOWN_ERR);
    }
}